<script type="text/javascript">
<?php
$expiryTime = $_SESSION["login_time"] + $_SESSION["timeout"];
$remainTime = $expiryTime - time();
echo "var remainTime = $remainTime;\n";
?>
    var oldTitle = document.title;
    document.title = oldTitle + " Timed Out: " + remainTime + " sec";

    function changeTitle() {
        remainTime = remainTime - 1;
        document.title = oldTitle + " Timed Out: " + remainTime + " sec";
        if (remainTime === 0) {
            var logoutMessage = encodeURIComponent("by timer");
            location = "logout.php?logoutMessage=" + logoutMessage;
        }
    }
    ;
    setInterval("changeTitle()", 1000);

</script>